/*
 * Copyright 2010 Kevin Bourrillion.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package kevinb9n.tobago;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Strings;

import java.io.PrintStream;

public class TextReport {
  private Island island;

  public TextReport(Island island) {
    this.island = checkNotNull(island);
  }

  public void printTo(PrintStream out) {
    out.println("Boards (first in the 11:00-3:00 position; then clockwise): " + island.boards);
    out.println("Compass orientation: " + (island.isCompassBackwards
        ? "reversed (backwards letters N and S)"
        : "normal (readable N and S)"));
    out.println();

    out.println("Landmarks:");

    out.println("  Huts (h):");
    for (IslandHex hex : island.hutLocations) {
      out.println("    " + hex);
    }

    out.println("  Palm trees (t):");
    for (IslandHex hex : island.palmTreeLocations) {
      out.println("    " + hex);
    }

    out.println("  Statues:");
    for (StatuePlacement placement : island.statuePlacements) {
      out.println("    " + placement);
    }

    out.println();

    out.println("  Coordinate (0, 0) is the hex of board '" + island.boards.get(0)
        + "' nearest the island center [" + island.islandHexAt(0, 0).terrain() + "].");
    out.println("  Coordinate (x, y) means x hexes in the 3:00 direction, y hexes toward 11:00.");
    out.println();

    out.println("Map:");

    for (int y = Board.MAX - 2; y > -Board.MAX; y--) {
      out.print(Strings.repeat("  ", Board.MAX - 2 - y));
      for (int x = -Board.MAX + 2; x < Board.MAX; x++) {
        IslandHex hex = island.islandHexAt(x, y);
        if (hex == null) {
          out.print("    ");
        } else {
          out.print(hex.terrain().character() + "" + hex.landmarkCharacter() + "  ");
        }
      }
      out.println();
      out.println();
    }
  }
}
